package rexsee.core.browser.clazz;

import rexsee.core.browser.Browser;
import android.content.Context;

public abstract class ExtensionListener {
	public final String[] extensions;
	public ExtensionListener(String[] listenedExtensions) {
		extensions = listenedExtensions;
		for (int i = 0; i < extensions.length; i++) {
			extensions[i] = extensions[i].toLowerCase();
		}
	}
	public abstract boolean shouldProcessOnline();
	public abstract boolean shouldProcessLocal();
	public abstract boolean shouldAddToHistory(String url);
	public abstract void run(Context context, Browser browser, String url);
	public boolean contains(String url) {
		if (extensions == null) return false;
		url = url.toLowerCase();
		if (url.contains("?")) url = url.substring(0, url.indexOf("?"));
		if (url.contains("#")) url = url.substring(0, url.indexOf("#"));
		if (url.contains("&")) url = url.substring(0, url.indexOf("&"));
		for (int i = 0; i < extensions.length; i++) {
			if (url.endsWith("." + extensions[i])) return true;
		}
		return false;
	}
}
